package org.jdarwinbots.logic;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;

public class DNA {
	private List<Operator> operators = new ArrayList<Operator>();
	
	public List<Operator> getOperators() {
		return Collections.unmodifiableList(operators);
	}


	private Map<String, Integer> customAliases = new HashMap<String, Integer>();
	
	public void addAlias(String name,int value) {
		customAliases.put(name, value);
	}
	
	private void addOperator(Operator o){
		this.operators.add(o);
	}
	
	public void addOperator(String name){
		this.addOperator(DefaultOperators.getOperator(name));
		
	}
	
	public void addAliasOperator(String name){

		Integer ca = customAliases.get(name);
		if(ca!=null){
			this.addOperator(ca);
			return;
		}
		this.addOperator(DefaultAliases.getValue(name));
	}
	
	public void addAliasReferenceOperator(String name){

		Integer ca = customAliases.get(name);
		if(ca!=null){
			this.addReferenceOperator(ca);
			return;
		}
		this.addReferenceOperator(DefaultAliases.getValue(name));
	}
	
	public void addOperator(int value){
		addOperator(DefaultOperators.getIntOperator(value));
	}
	public void addReferenceOperator(int value){
		addOperator(DefaultOperators.getRefOperator(value));
	}
	
	
	public void execute(int[] memory, Stack<Integer> intstack, Stack<Boolean> boolstack){
		for(Operator o:operators){
			o.execute(memory, intstack, boolstack);
		}
	}
}
